package com.apes.auto.car.model;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName ImportCar
 * @Description TODO
 * @Author pengyb
 * @Date 2019/7/18 11:49
 * @Version 1.0
 **/
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = ImportCar.CONST_TABLE_NAME)
public class ImportCar extends Model {
    public static final String CONST_TABLE_NAME = "import_car";
    @Id
    @Column(name = "id", length = 16)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "车型导入表")
    private String id;

    @Column(name = "import_date", length = 120)
    @Comment("名称")
    private String name; //名称

    @OneToMany(mappedBy = "importCar", cascade = CascadeType.ALL, orphanRemoval = true)
    private List<ImportCarExecute> importCarExecutes = new ArrayList<>();

    public List<ImportCarExecute> getImportCarExecutes() {
        for (ImportCarExecute importCarExecute : importCarExecutes) {
            importCarExecute.setImportCar(this);
        }
        return importCarExecutes;
    }

}
